package top.mcwebsite.playandroid.business.qa.ui

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import top.mcwebsite.playandroid.business.qa.model.QAReplayComment
import top.mcwebsite.playandroid.strings.Plurals
import top.mcwebsite.playandroid.strings.Str


@Composable
fun CommentHeader(
    comment: QAReplayComment,
    modifier: Modifier
) {

    Text(
        text = pluralStringResource(
            id = Plurals.comment_count,
            comment.replyComments.size,
            comment.replyComments.size
        ),
        modifier = modifier
    )
    Row(
        verticalAlignment = Alignment.CenterVertically,
        modifier = Modifier.padding(horizontal = 10.dp, vertical = 8.dp)
    ) {
        FakeAvatar(name = comment.userName, modifier = Modifier.size(32.dp))
        Box(
            modifier = Modifier
                .padding(start = 10.dp)
                .height(32.dp)
                .fillMaxWidth()
                .background(
                    color = Color.Gray.copy(alpha = 0.2f),
                    shape = MaterialTheme.shapes.extraLarge
                ),
            contentAlignment = Alignment.CenterStart
        ) {
            Text(
                text = stringResource(id = Str.write_comment),
                style = MaterialTheme.typography.labelMedium.copy(
                    color = MaterialTheme.typography.labelMedium.color.copy(
                        alpha = 0.5f
                    )
                ),
                modifier = Modifier.padding(start = 15.dp)
            )
        }
    }
}

@Composable
fun Comment(
    comment: QAReplayComment,
    modifier: Modifier = Modifier
) {
    Row(
        modifier = modifier
    ) {
        FakeAvatar(name = comment.getDisplayUsername(), modifier = Modifier.size(32.dp))
        Column(
            modifier = Modifier.padding(start = 10.dp)
        ) {
            Text(text = comment.getDisplayUsername(), style = MaterialTheme.typography.titleMedium)
            // TODO 后续可以做更好的处理
            Text(text = (if (comment.toUserName.isNotEmpty()) "@${comment.toUserName} " else "") + comment.content)
            Text(
                text = comment.niceDate,
                style = MaterialTheme.typography.labelMedium.copy(
                    color = MaterialTheme.typography.labelMedium.color.copy(alpha = 0.5f)
                ),
                modifier = Modifier.padding(top = 3.dp)
            )
        }
    }
}
